package com.linzelin.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录用拦截器
 * @author 君未洋
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //如果登录成功应该有对应的session,使用session去配置对应的内容
        Object user = request.getSession().getAttribute("user");
        if (user==null) {
            request.setAttribute("msg", "还没登录呢,你想干什么");
            request.getRequestDispatcher("/index").forward(request, response);
            return false;
        }
        return true;
    }
}
